package rdp.auto.clear;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;


import java.util.List;

import rdp.RDPUtil;

public class AUTOClearMain extends BukkitRunnable {
    private JavaPlugin plugin;
    private FileConfiguration conf;
    private int counter;
    private int period, interim;
    private List<String> content;

    @Override
    public void run() {
        if (counter == period) {
            new AUTOClearItem().open(conf, plugin);
        } else if (counter % interim == 0 || period - counter == 1)
            RDPUtil.NOTICE(content.get(0).replace("*-*", String.valueOf(period - counter)));
        counter = counter == period ? 0 : counter + 1;
    }

    public void open(FileConfiguration conf, JavaPlugin plugin) {
        this.plugin = plugin;
        this.conf = conf;
        this.period = conf.getInt("period");
        this.interim = conf.getInt("interim");
        this.content = conf.getStringList("content");
        this.counter = 0;
        runTaskTimer(plugin, 0, conf.getInt("unit") * 20);
    }
}
